﻿using System;
using UFIDA.U9.WSS.ProxyService.Exceptions;
using UFSoft.UBF;
using UFSoft.UBF.Service.Base;

namespace UFIDA.U9.WSS.ProxyTestService.Utils
{
    public static class ProxyHelper
    {
        /// <summary>
        ///     获取请求代理对象
        /// </summary>
        /// <param name="proxyType"></param>
        /// <returns></returns>
        public static ProxyBase GetProxyBaseObject(string proxyType)
        {
            Type loadType = GetType(proxyType);
            if (loadType == null)
                throw new WSException(ExceptionCodes.ProxyServiceProxyTypePropertyIsIncorrect,
                    "proxyType is incorrect");
            return Activator.CreateInstance(loadType) as ProxyBase;
        }

        /// <summary>
        ///     获取请求代理对象
        /// </summary>
        /// <param name="proxyType"></param>
        /// <returns></returns>
        public static Type GetType(string proxyType)
        {
            if (proxyType == null)
                throw new WSException(ExceptionCodes.ServiceRequestDataFormatException, "proxyType is null");
            return TypeManager.TypeLoader.LoadType(proxyType);
        }
    }
}